package linwen.wang.redis.jedis;

import org.junit.Test;
import redis.clients.jedis.Jedis;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName JedisHash
 * @Description
 * @Author lin
 * @Date 2022/3/2 下午9:39
 * @Version V1.0
 */
public class JedisHash {
    //Hash
    @Test
    public void test(){
        String host = "112.74.87.142";
        String password = "123456";
        Jedis jedis = new Jedis(host);
        jedis.auth(password);
        Map<String,String> map = new HashMap<>();
        map.put("name", "Alan");
        map.put("age", "22");
        jedis.hmset("user",map);
        jedis.hset("user", "gender", "male");
        //获取单个数据
        System.out.println(jedis.hget("user", "age"));

        //获取多个数据
        System.out.println(jedis.hmget("user", "name","gender"));

        //获取所有数据
        System.out.println(jedis.hgetAll("user"));

        //获取所有的键
        System.out.println(jedis.hkeys("user"));

        //获取所有的值
        System.out.println(jedis.hvals("user"));

        jedis.close();

    }

}
